package com.zc.order.controller;


import com.zc.order.service.PayLogService;
import com.zc.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 支付日志表 前端控制器
 * </p>
 *
 * @author cong
 * @since 2022-12-04
 */
@RestController
@RequestMapping("/order/paylog")
@CrossOrigin
public class PayLogController {
	@Autowired
	private PayLogService payLogService;


	// 创建微信收款二维码
	@GetMapping("/createNative/{orderNo}")
	public R createNative(@PathVariable String orderNo) {
		Map map = payLogService.createNative(orderNo);
		return R.ok().data(map);
	}

	// 查询支付状态
	@GetMapping("/getPayStatus/{orderNo}")
	public R getPayStatus(@PathVariable String orderNo){
		Map<String, String> map = payLogService.getPayStatus(orderNo);
		if (map == null) {
			return R.error();
		}

		// 支付成功
		if(map.get("trade_state").equals("SUCCESS")) {
			payLogService.updateOrderStatus(map);
			return R.ok();
		}
		return R.ok().code(25000).message("支付中");
	}

}

